//
//  CompletionCell.m
//  Recycling
//
//  Created by jzd on 2018/5/19.
//  Copyright © 2018年 宋佳. All rights reserved.
//

#import "CompletionCell.h"
#import "orderModel.h"

@interface CompletionCell ()
@property (weak, nonatomic) IBOutlet UIButton *telBut;//用户电话
@property (weak, nonatomic) IBOutlet UILabel *userName;//用户名
@property (weak, nonatomic) IBOutlet UIButton *userAddress;//用户地址
@property (weak, nonatomic) IBOutlet UILabel *transactionType;//绿色的收
@property (weak, nonatomic) IBOutlet UILabel *goodsName;//回收物品的名称
@property (weak, nonatomic) IBOutlet UILabel *goodPrice;//价格
@property (weak, nonatomic) IBOutlet UILabel *agreementTime;//预约时间
@property (weak, nonatomic) IBOutlet UILabel *completionTime;//完工时间
@property (weak, nonatomic) IBOutlet UILabel *remindCount;//催单次数



@end
@implementation CompletionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.contentView.layer.cornerRadius = 5;
    self.contentView.layer.masksToBounds = YES;
}
-(void)setFrame:(CGRect)frame{
    frame = CGRectMake(frame.origin.x+5, frame.origin.y+5, frame.size.width-10, frame.size.height-10);
    [super setFrame:frame];
}
-(void)setModel:(orderModel *)model{
    _model = model;
    
    [self.telBut setTitle:model.UserTel forState:UIControlStateNormal];
    NSString *str = self.telBut.titleLabel.text;
    if (str.length != 0) {
        NSMutableAttributedString *tncString = [[NSMutableAttributedString alloc]initWithString:str];
        [tncString addAttribute:NSUnderlineStyleAttributeName
                          value:@(NSUnderlineStyleSingle)
                          range:(NSRange){0,[tncString length]}];
        //此时如果设置字体颜色要这样
        [tncString addAttribute:NSForegroundColorAttributeName value:TITLECOLOR  range:NSMakeRange(0,[tncString length])];
        
        //设置下划线颜色...
        [tncString addAttribute:NSUnderlineColorAttributeName value:TITLECOLOR range:(NSRange){0,[tncString length]}];
        [self.telBut setAttributedTitle:tncString forState:UIControlStateNormal];
    }
    
    self.userName.text = model.UserName;
    [self.userAddress setTitle:model.UserAddress forState:UIControlStateNormal];
    self.goodsName.text = [NSString stringWithFormat:@"%@%@%@",model.ProBrandName,model.ProSpecName,model.ProTypeName];
    self.goodPrice.text = [NSString stringWithFormat:@"¥%.2f",model.MessagePrice];
    self.agreementTime.text = model.AppointmentDate;
    self.completionTime.text = model.CompleteDate;
    self.remindCount.text = [NSString stringWithFormat:@"%d",model.RemindCount];
}

- (IBAction)telOnClick:(UIButton *)sender {
    NSString *resourceSpecifier = self.telBut.currentAttributedTitle.string;
    NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@",resourceSpecifier];
    if (@available(iOS 10.0, *)) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone] options:@{} completionHandler:nil];
    } else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
    }
    
//    NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", resourceSpecifier];
//    /// 防止iOS 10及其之后，拨打电话系统弹出框延迟出现
//    dispatch_async(dispatch_get_global_queue(0, 0), ^{
//        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
//    });
}
- (IBAction)addressOnClick:(UIButton *)sender {
    [[NSNotificationCenter defaultCenter]postNotificationName:addressOnClickNotification object:self userInfo:nil];
}


@end
